package filter;

import java.io.IOException;
import java.nio.channels.NonReadableChannelException;
import java.sql.Date;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpFilter;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.xml.crypto.Data;


@WebFilter(filterName = "/LogFilter")
public class LogFilter extends HttpFilter implements Filter {
       
    
    public LogFilter() {
        super();
        
    }

	@Override
	public void destroy() {
		System.out.println("LogFilter的销毁");
	}

	@Override
	public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
		HttpServletRequest req = (HttpServletRequest) request;
		
		String uri = req.getRequestURI();
		
		String ip = request.getRemoteAddr();
		
		System.out.println("请求到达：URI=" + uri + ",IP=" + ip);
		
		
		chain.doFilter(request, response);
		System.out.println("相应完成：URI=" +uri);
	}

	
	public void init(FilterConfig fConfig) throws ServletException {
		System.out.println("LogFilter 的初始化");
	}

}
